import pygame, sys, math

class Shot(pygame.sprite.Sprite):
    def __init__(self, image, direction, pos = (0,0), screensize = [800,600]):
        pygame.sprite.Sprite.__init__(self, self.containers)
        print"?????????????????????????????????????"
        self.image = pygame.image.load(image)
        self.image = pygame.transform.scale(self.image, [10,5])
        self.rect = self.image.get_rect()
        self.realx = pos[0]
        self.realy = pos[1]
        self.x = pos[0]
        self.y = pos[1]
        self.place(pos)
        self.screensize = screensize
        if direction == "right":
            self.speedx = 10
        else:
            self.speedx = -10
        self.speedy = 0
        self.scrollingx = False
        self.scrollingy = False
        self.offsetx = 0
        self.offsety = 0
        
    def place(self, pos):
        self.rect.center = pos
        
    def fixLocation(self, x, y):
        self.x += x
        self.y += y
        
    def update(*args):
        self = args[0]
        self.playerspeedx = args[2]
        self.playerspeedy = args[3]
        self.scrollingx = args[4]
        self.scrollingy = args[5]
        self.collideWall()
        self.move()
        print "--------------------------------------"
        
    def collide(self, other):
        if self.rect.right > other.rect.left and self.rect.left < other.rect.right:
            if self.rect.bottom > other.rect.top and self.rect.top < other.rect.bottom:
                if self.radius + other.radius > self.distanceToPoint(other.rect.center):
                    self.living = False
                    other.kill()
                    return True
        return False
    
    def collideWall(self):
        width = self.screensize[0]
        height = self.screensize[1]
        #print self.rect
        #raw_input(">")
        if self.rect.left < 0:
            self.kill()
        if self.rect.right > width:
            self.kill()
        if self.rect.top < 0:
            self.kill()
        if self.rect.bottom > height:
            self.kill()
        
    def move(self):
        self.realx += self.speedx
        
        if self.scrollingx:
            self.offsetx -= self.playerspeedx
        if self.scrollingy:
            self.offsety -=  self.playerspeedy
        
        self.x = self.realx + self.offsetx
        self.y = self.realy + self.offsety
            
        self.rect.center = (round(self.x), round(self.y))